﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Threading;
using Utilities.QuickSql;
using MySql.Data;

namespace Deviseur_Cs2i_Car
{
    public partial class AdminContenance : Form
    {
        public AdminContenance()
        {
            InitializeComponent();

            Thread ContenanceThread = new Thread(new ThreadStart(getAllContenance_Thread));
            ContenanceThread.Start();
        }

        private void getAllContenance_Thread()
        {
            Invoke(new MethodInvoker(getAllContenance));         
        }

        private void getAllContenance()
        {
            Table ContenanceVoiture = Program.Db.QueryTable("SELECT * FROM CONTENANCE");

            this.dataGridView1.Rows.Clear();

            foreach (Record r in ContenanceVoiture)
                this.dataGridView1.Rows.Add(r.Values[0], r.Values[1]);
        }

        private void buttonAddContenance_Click_1(object sender, EventArgs e)
        {
            AddContenance FenAddContenance = new AddContenance();
            FenAddContenance.ShowDialog();
        }

        private void AdminContenance_Activated(object sender, EventArgs e)
        {
            Thread ContenanceThread = new Thread(new ThreadStart(getAllContenance_Thread));
            ContenanceThread.Start();
        }

        private void buttonDelContenance_Click(object sender, EventArgs e)
        {
            CONTENANCE delContenance = new CONTENANCE();
            delContenance.delete_Contenance(Convert.ToInt32(this.dataGridView1.SelectedRows[0].Cells[0].Value.ToString()));
            Thread ContenanceThread = new Thread(new ThreadStart(getAllContenance_Thread));
            ContenanceThread.Start();
        }

        private void buttonDelContenance_Click_1(object sender, EventArgs e)
        {
            CONTENANCE delContenance = new CONTENANCE();
            delContenance.delete_Contenance(Convert.ToInt32(this.dataGridView1.SelectedRows[0].Cells[0].Value.ToString()));
            Thread TypeThread = new Thread(new ThreadStart(getAllContenance_Thread));
            TypeThread.Start();
        }

        private void buttonModifContenance_Click(object sender, EventArgs e)
        {
            AddContenance FenAddHTDI = new AddContenance(Convert.ToInt32(this.dataGridView1.SelectedRows[0].Cells[0].Value.ToString()));
            FenAddHTDI.ShowDialog();
        }
    }
}
